package ActorObj;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.DragListener;

public class RotationGroup extends Group {

	private float r=280;
	public float speed=0.1f;
	public float oldDragY=0;
	
	public RotationGroup(Actor btn1,Actor btn2,Actor btn3,Actor btn4,Actor btn5,Actor btn6) {
		initBtn1OriginY(btn1,0-45);
		initBtn1OriginY(btn2,60-45);
		initBtn1OriginY(btn3,120-45);
		initBtn1OriginY(btn4,180-45);
		initBtn1OriginY(btn5,240-45);
		initBtn1OriginY(btn6,300-45);
		
		addActor(btn1);
		addActor(btn2);
		addActor(btn3);
		addActor(btn4);
		addActor(btn5);
		addActor(btn6);
		
		
	}
	
	public void init() {
		speed=0.1f;
		oldDragY=0;
	}
	
	
	@Override
	public void act(float arg0) {
		// TODO Auto-generated method stub
		super.act(arg0);
//		if(speed>=1)
//		{
//			speed-=0.5;
//		}
//		else {
//			if( getRotation()%60>=43 && getRotation()%60<=45 )
//			{
//				speed=0f;
//				setRotation( (45- (getRotation()%60) )+getRotation() );
//			}
//		}
		if(speed>0.1)
		{
			speed-=0.01;
		}
		if(speed<-0.1)
		{
			speed+=0.01;
		}
	}
	
	@Override
	public void draw(SpriteBatch batch, float parentAlpha) {
		// TODO Auto-generated method stub
		
		super.draw(batch, parentAlpha);
		setRotation(getRotation()+speed);
	}
	
	private void initBtn1OriginY(Actor btn,float Rotation)
	{
		double degrees= (Math.PI*(Rotation+180)/180);
		double x=Math.cos(degrees)*r;
		double y=Math.sin(degrees)*r;
		btn.setX((float)x);
		btn.setY((float)y);
		
		btn.setRotation(Rotation);
	}
	
	@Override
	public Actor hit(float arg0, float arg1, boolean arg2) {
		// TODO Auto-generated method stub
		
		if(Math.sqrt((arg0)*(arg0)+(arg1)*(arg1))<256+r)
		{
			Actor hitActor=super.hit(arg0, arg1, arg2);
			if(hitActor==null)
				return this;
			else {
				return hitActor;
			}
		}
		return super.hit(arg0, arg1, arg2);
	}
}
